@page "/settings/apps"
@inherits MainBase
@inject IJSRuntime JsRuntime
@inject ILogger<Apps> Logger
@using AliasVault.Shared.Core.BrowserExtensions
@using AliasVault.Shared.Core.MobileApps
@using Microsoft.Extensions.Localization

<LayoutPageTitle>@Localizer["PageTitle"]</LayoutPageTitle>

<PageHeader
    BreadcrumbItems="@BreadcrumbItems"
    Title="@Localizer["PageTitle"]"
    Description="@Localizer["PageDescription"]">
</PageHeader>

<div class="p-4 mb-4 mx-4 bg-white border border-gray-200 rounded-lg shadow-sm dark:border-gray-700 sm:p-6 dark:bg-gray-800">
    <div class="mb-6">
        <h3 class="text-lg font-medium text-gray-900 dark:text-white mb-2">@Localizer["BrowserExtensionsTitle"]</h3>
        <p class="text-gray-600 dark:text-gray-400">
            @Localizer["BrowserExtensionsDescription"]
        </p>
    </div>

    <div class="mb-8">
        <div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
            @foreach (var extension in AliasVault.Shared.Core.BrowserExtensions.Constants.Extensions
                .Where(x => x.Key != BrowserType.Unknown)
                .Select(x => x.Value))
            {
                <div class="p-4 border rounded-lg dark:border-gray-700 flex justify-between items-center">
                    <div class="flex items-center">
                        <img src="@extension.IconPath" alt="@extension.Name" class="w-8 h-8 mr-3">
                        <h4 class="text-lg font-medium text-gray-900 dark:text-white">@extension.Name</h4>
                    </div>
                    @if (extension.IsAvailable)
                    {
                        <a href="@extension.DownloadUrl"
                           target="_blank"
                           class="inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 focus:ring-4 focus:ring-primary-200 dark:focus:ring-primary-900">
                            @Localizer["InstallButton"]
                        </a>
                    }
                    else
                    {
                        <span class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-500 bg-gray-100 rounded-lg dark:text-gray-400 dark:bg-gray-800">
                            @Localizer["ComingSoonText"]
                        </span>
                    }
                </div>
            }
        </div>
    </div>

    <div class="mb-6">
        <h3 class="text-lg font-medium text-gray-900 dark:text-white mb-2">@Localizer["MobileAppsTitle"]</h3>
        <p class="text-gray-600 dark:text-gray-400 mb-4">
            @Localizer["MobileAppsDescription"]
        </p>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
        @foreach (var app in AliasVault.Shared.Core.MobileApps.Constants.MobileApps)
        {
            <div class="p-4 border rounded-lg dark:border-gray-700 flex justify-between items-center">
                <div class="flex items-center">
                    <img src="@app.IconPath" alt="@app.Name" class="w-8 h-8 mr-3">
                    <h4 class="text-lg font-medium text-gray-900 dark:text-white">@app.Name</h4>
                </div>
                @if (app.IsAvailable)
                {
                    <a href="@app.DownloadUrl"
                       target="_blank"
                       class="inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-primary-600 rounded-lg hover:bg-primary-700 focus:ring-4 focus:ring-primary-200 dark:focus:ring-primary-900">
                        @Localizer["DownloadButton"]
                    </a>
                }
                else
                {
                    <span class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-500 bg-gray-100 rounded-lg dark:text-gray-400 dark:bg-gray-800">
                        @Localizer["ComingSoonText"]
                    </span>
                }
            </div>
        }
    </div>
</div>

@code {
    private IStringLocalizer Localizer => LocalizerFactory.Create("Pages.Main.Settings.Apps", "AliasVault.Client");

    /// <inheritdoc />
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        BreadcrumbItems.Add(new BreadcrumbItem { DisplayName = Localizer["BreadcrumbTitle"] });
    }
}
